# Generated by Django 2.2.12 on 2020-05-18 13:09

from django.db import migrations

wanted_urls = {
    "https://dropbox.com/?": "Factures Logistiques (Dropbox)",
    "https://sbb.ch/?": "Frais de trajet (CFF Business)",
}


def add_initial_validation_urls(apps, schema_editor):
    # We can't import the MonthlyCantonalValidationUrl model directly as it may be a newer
    # version than this migration expects. We use the historical version.
    MCVU = apps.get_model("salary", "MonthlyCantonalValidationUrl")
    for url, name in wanted_urls.items():
        m = MCVU()
        m.set_current_language("fr")
        m.url = url
        m.name = name
        m.save()


def empty_validation_urls(apps, schema_editor):
    # We can't import the MonthlyCantonalValidationUrl model directly as it may be a newer
    # version than this migration expects. We use the historical version.
    MCVU = apps.get_model("salary", "MonthlyCantonalValidationUrl")
    MCVU.objects.filter(url__in=wanted_urls.keys()).delete()


class Migration(migrations.Migration):
    dependencies = [
        ("salary", "0010_monthlycantonalvalidation_validated_urls"),
    ]

    operations = [
        migrations.RunPython(add_initial_validation_urls, empty_validation_urls)
    ]
